package com.sky.controller.admin;

import com.sky.dao.CancelDTO;
import com.sky.dao.ConfirmDTO;
import com.sky.dao.OrderQueryDTO;
import com.sky.dao.RejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderVO;
import com.sky.vo.StatisticVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController(value = "adminOrderController")
@Slf4j
@Api(tags = "后台-订单管理")
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation("訂單搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> search(OrderQueryDTO orderQueryDTO) {
        PageResult pageResult = orderService.conditionSearch(orderQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation("訂單详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> details(@PathVariable("id") Long id) {
        OrderVO orderVO = orderService.orderDetail(id);
        return Result.success(orderVO);
    }

    @ApiOperation("各個狀態訂單數量")
    @GetMapping("/statistics")
    public Result<StatisticVO> statistics() {
        StatisticVO statisticVO = orderService.statistics();
        return Result.success(statisticVO);
    }

    @ApiOperation("接單")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody ConfirmDTO confirmDTO) {
        orderService.confirm(confirmDTO);
        return Result.success();
    }

    @ApiOperation("拒單")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody RejectionDTO rejectionDTO) {
        orderService.rejection(rejectionDTO);
        return Result.success();
    }

    @ApiOperation("派送訂單")
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable("id") Long id) {
        orderService.delivery(id);
        return Result.success();
    }

    @ApiOperation("取消訂單")
    @PutMapping("/cancel")
    public Result cancel(@RequestBody CancelDTO cancelDTO) {
        orderService.cancel(cancelDTO);
        return Result.success();
    }

    @ApiOperation("完成訂單")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable("id") Long id) {
        orderService.complete(id);
        return Result.success();
    }
}
